"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
const maishu_node_mvc_1 = require("maishu-node-mvc");
const common_1 = require("../common");
const errors_1 = require("../errors");
const common_2 = require("common");
let Setting = class Setting {
    async item(appId, dc) {
        if (!appId)
            throw errors_1.errors.cannotGetApplicationId();
        let setting = await dc.settings.findOne(appId);
        return setting;
    }
    async set(appId, dc, { item }) {
        if (!appId)
            throw errors_1.errors.cannotGetApplicationId();
        if (!item)
            throw errors_1.errors.routeDataFieldNull("item");
        let setting = await dc.settings.findOne(appId);
        if (setting == null) {
            setting = item;
            setting.id = appId;
        }
        else {
            Object.assign(setting, item);
        }
        await dc.settings.save(setting);
        return { id: setting.id };
    }
};
__decorate([
    maishu_node_mvc_1.action(),
    __param(0, common_2.currentAppId), __param(1, common_1.weixinDataContext)
], Setting.prototype, "item", null);
__decorate([
    maishu_node_mvc_1.action(),
    __param(0, common_2.currentAppId), __param(1, common_1.weixinDataContext), __param(2, maishu_node_mvc_1.routeData)
], Setting.prototype, "set", null);
Setting = __decorate([
    maishu_node_mvc_1.controller("setting")
], Setting);
exports.Setting = Setting;
